package com.ruoyi.system.api;

import com.ruoyi.system.api.model.UserDto;
import com.ruoyi.system.api.domain.WxUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
import com.ruoyi.system.api.model.LoginUser;

/**
 * 用户服务
 *
 * @author ruoyi
 * contextId 用于区分不同的 Feign 客户端实例,============= value 属性用于指定目标服务的名称或标识符(客户端是与名为 "userService" 的服务进行通信的)
 */
@Component
@Repository
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
    /**
     * 通过用户名查询用户信息
     *
     * @param username 用户名
     * @param source   请求来源
     * @return 结果
     */
    @GetMapping("/user/info/{username}")
    public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 注册用户信息
     *
     * @param sysUser 用户信息
     * @param source  请求来源
     * @return 结果
     */
    @PostMapping("/user/register")
    public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 根据 openid 查询客户信息
     *
     * @param openid  用户唯一标识
     * @param source 请求来源 FROM_SOURCE   必须是内部innerauth  内部来源
     * @return
     */
    @GetMapping("/user/getInfoByOpenid/{openid}")
    public R<LoginUser> getInfoByOpenid(@PathVariable("openid") String openid, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);


    @PostMapping("/user/getInfoByPhone")
    public R<WxUser> getInfoByPhone( @RequestBody UserDto userDto,  @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    /**
     * 新增微信用户信息
     *
     * @param sysUser 用户信息
     * @param source  请求来源
     * @return 结果
     */
    @PostMapping("/user/addWxUser")
    public R<SysUser>  addWxUser(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);

    @PostMapping("/user/chooseIdentity")
    public R<Integer> chooseIdentity(@RequestBody SysUser identityBody, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}